local ty_1v2_ly = fk.CreateSkill {
    name = "ty_1v2_ly&",
    tags = { Skill.Compulsory },
}

Fk:loadTranslationTable {
    ["ty_1v2_ly&"] = "洛阳",
    [":ty_1v2_ly&"] = "锁定技，每轮开始时，你选择对一名联军造成0~2点伤害，若伤害值为0，你摸两张牌，于本轮结束时可再次发动该技能，并将伤害值改为1。",
}

ty_1v2_ly:addEffect(fk.RoundStart, {
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(ty_1v2_ly.name)
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function(p)
            return p.role == "rebel"
        end)
        local tos = room:askToChoosePlayers(player, {
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "洛阳：请选择一名联军，对其造成0~2点伤害",
            skill_name = ty_1v2_ly.name,
        })
        if #tos > 0 then
            event:setCostData(self, { tos = tos })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        local x = math.random(0, 2)
        if x == 0 then
            player:drawCards(2, ty_1v2_ly.name)
            room:setPlayerMark(player, "ty_1v2_ly", 1)
        else
            room:damage({
                from = player,
                to = event:getCostData(self).tos[1],
                damage = x,
                damageType = fk.FireDamage,
                skillName = ty_1v2_ly.name
            })
        end
    end,
})
ty_1v2_ly:addEffect(fk.RoundEnd, {
    can_trigger = function(self, event, target, player, data)
        return player:hasSkill(ty_1v2_ly.name) and player:getMark("ty_1v2_ly") > 0
    end,
    on_cost = function(self, event, target, player, data)
        local room = player.room
        local targets = table.filter(room.alive_players, function(p)
            return p.role == "rebel"
        end)
        local tos = room:askToChoosePlayers(player, {
            targets = targets,
            min_num = 1,
            max_num = 1,
            prompt = "洛阳：请选择一名联军，对其造成1点伤害",
            skill_name = ty_1v2_ly.name,
        })
        if #tos > 0 then
            event:setCostData(self, { tos = tos })
            return true
        end
    end,
    on_use = function(self, event, target, player, data)
        local room = player.room
        room:damage({
            from = player,
            to = event:getCostData(self).tos[1],
            damage = 1,
            damageType = fk.FireDamage,
            skillName = ty_1v2_ly.name
        })
    end,
})


return ty_1v2_ly
